package ebj.common.docparser.xml;

import com.thoughtworks.xstream.XStream;

public class Test {
	// static String xml_code = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><request type=\"textAd\"><htmlString skipoverlaybutton=\"balabala\"><![CDATA[<body style=\"text-align:center;margin:0;padding:0;\"><a href=\"http://account.mobfox.com/activation-info.php\" target=\"_self\"><img src=\"http://creative1cdn.mobfox.com/mftext/320x480/315C93/fff&text=MobFox%20Test%20Ad\" border=\"0\"/></a></body>]]></htmlString><clicktype>inapp</clicktype><clickurl><![CDATA[http://account.mobfox.com/activation-info.php]]></clickurl><urltype>link</urltype><refresh>60</refresh><scale>no</scale><skippreflight>yes</skippreflight></request>";
	static String xml_code = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><request type=\"textAd\"><htmlString skipoverlaybutton=\"balabala\"><![CDATA[<body style=\"text-align:center;margin:0;padding:0;\"><a href=\"http://account.mobfox.com/activation-info.php\" target=\"_self\"><img src=\"http://creative1cdn.mobfox.com/mftext/320x480/315C93/fff&text=MobFox%20Test%20Ad\" border=\"0\"/></a></body>]]></htmlString><clicktype>inapp</clicktype><clickurl><![CDATA[http://account.mobfox.com/activation-info.php]]></clickurl><urltype>link</urltype><refresh>60</refresh><scale>no</scale><skippreflight>yes</skippreflight></request>";
	public static void main(String[] args) {
		XStream xs = XStreamFactory.init(false);
		xs.alias("request", AdResponseContents.class);
		xs.processAnnotations(AdResponseContents.class);
		AdResponseContents response = (AdResponseContents) xs.fromXML(xml_code);
		System.out.println(response.getHtmlString().getSkipoverlaybutton());
		System.out.println(response.getType());
		
		System.out.println("######################");
		
		AdResponse adResponse = new AdResponse();
		adResponse.setType("imageAd");
		adResponse.setClicktype("aaa");
		adResponse.setRefresh(100);
		HtmlString htmlString = new HtmlString();
		htmlString.setSkipoverlaybutton("testSkipoverlaybutton");
		htmlString.setContents("<html><body>");
		adResponse.setHtmlString(htmlString);
		
		XStream xStream = XStreamFactory.init(true);
		// 使注解生效，以下两种方式等效
		// xStream.processAnnotations(AdResponse.class);
		xStream.processAnnotations(new Class[]{AdResponse.class});
		xStream.alias("request", AdResponse.class);
		System.out.println("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\r\n" + xStream.toXML(adResponse));
	}

}
